home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / cxref-1.001 / cxref-1~ / cxref / file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-24  |  4.0 KB  |  175 lines

  1. /***************************************
  2.   $Header: /home/amb/cxref/RCS/file.c 1.7 1996/02/24 14:53:10 amb Exp $
  3.  
  4.   C Cross Referencing & Documentation tool. Version 1.0
  5.  
  6.   Sets up the top level File structure.
  7.   ******************/ /******************
  8.   Written by Andrew M. Bishop
  9.  
  10.   This file Copyright 1995,96 Andrew M. Bishop
  11.   It may be distributed under the GNU Public License, version 2, or
  12.   any higher version.  See section COPYING of the GNU Public license
  13.   for conditions under which this file may be redistributed.
  14.   ***************************************/
  15.  
  16. /*+ To control the debugging in this file. +*/
  17. #define DEBUG 0
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. #include "memory.h"
  24. #include "datatype.h"
  25. #include "cxref.h"
  26.  
  27. /*+ This contains the File that is currently being documented to allow the other functions access to it. +*/
  28. File CurFile=NULL;
  29.  
  30. /*++++++++++++++++++++++++++++++++++++++
  31.   Creates a new File structure, and sets CurFiel to point to it.
  32.  
  33.   File NewFile Returns the new file structure.
  34.  
  35.   char* name The name of the file.
  36.   ++++++++++++++++++++++++++++++++++++++*/
  37.  
  38. File NewFile(char* name)
  39. {
  40.  CurFile=(File)Malloc(sizeof(struct _File));
  41.  
  42.  CurFile->comment=NULL;
  43.  CurFile->name=MallocString(name);
  44.  CurFile->includes=NULL;
  45.  CurFile->defines=NULL;
  46.  CurFile->typedefs=NULL;
  47.  CurFile->variables=NULL;
  48.  CurFile->functions=NULL;
  49.  InitStringList(&CurFile->inc_in);
  50.  InitStringList(&CurFile->f_refs);
  51.  InitStringList(&CurFile->v_refs);
  52.  
  53.  return(CurFile);
  54. }
  55.  
  56.  
  57. /*++++++++++++++++++++++++++++++++++++++
  58.   Called when a file comment has been seen. Only the first of multiple comments in a file are used.
  59.  
  60.   char* comment The comment for the file.
  61.   ++++++++++++++++++++++++++++++++++++++*/
  62.  
  63. void SeenFileComment(char* comment)
  64. {
  65.  if(!CurFile->comment)
  66.     CurFile->comment=MallocString(comment);
  67. }
  68.  
  69.  
  70. /*++++++++++++++++++++++++++++++++++++++
  71.   Deletes a file structure.
  72.  
  73.   File file The file structure to be deleted.
  74.  
  75.   This is required to go through each of the elements in the File structure and delete each of them in turn.
  76.   ++++++++++++++++++++++++++++++++++++++*/
  77.  
  78. void DeleteFile(File file)
  79. {
  80.  if(file->comment) Free(file->comment);
  81.  Free(file->name);
  82.  
  83.  DeleteStringList(&file->inc_in);
  84.  DeleteStringList(&file->f_refs);
  85.  DeleteStringList(&file->v_refs);
  86.  
  87.  if(file->includes)
  88.    {
  89.     Include p=file->includes,n;
  90.     do{
  91.        n=p->next;
  92.        if(p->comment) Free(p->comment);
  93.        Free(p->name);
  94.        if(p->includes)          /* Add the included files to the end instead of recursing. */
  95.          {
  96.           AddToLinkedList(n,Include,p->includes);
  97.           p->includes=NULL;
  98.          }
  99.        Free(p);
  100.        p=n;
  101.       }
  102.     while(p);
  103.    }
  104.  
  105.  if(file->defines)
  106.    {
  107.     Define p=file->defines,n;
  108.     do{
  109.        n=p->next;
  110.        if(p->comment) Free(p->comment);
  111.        Free(p->name);
  112.        if(p->value) Free(p->value);
  113.        DeleteStringList2(&p->args,1);
  114.        Free(p);
  115.        p=n;
  116.       }
  117.     while(p);
  118.    }
  119.  
  120.  if(file->typedefs)
  121.    {
  122.     Typedef p=file->typedefs,n;
  123.     do{
  124.        n=p->next;
  125.        if(p->comment) Free(p->comment);
  126.        Free(p->name);
  127.        if(p->type) Free(p->type);
  128.        if(p->sutype) DeleteStructUnion(p->sutype);
  129.        Free(p);
  130.        p=n;
  131.       }
  132.     while(p);
  133.    }
  134.  
  135.  if(file->variables)
  136.    {
  137.     Variable p=file->variables,n;
  138.     do{
  139.        n=p->next;
  140.        if(p->comment) Free(p->comment);
  141.        Free(p->name);
  142.        Free(p->type);
  143.        if(p->defined) Free(p->defined);
  144.        DeleteStringList(&p->visible);
  145.        DeleteStringList(&p->used);
  146.        Free(p);
  147.        p=n;
  148.       }
  149.     while(p);
  150.    }
  151.  
  152.  if(file->functions)
  153.    {
  154.     Function p=file->functions,n;
  155.     do{
  156.        n=p->next;
  157.        if(p->comment) Free(p->comment);
  158.        Free(p->name);
  159.        if(p->type)    Free(p->type);
  160.        if(p->protofile) Free(p->protofile);
  161.        if(p->cret)    Free(p->cret);
  162.        DeleteStringList2(&p->args,1);
  163.        DeleteStringList(&p->calls);
  164.        DeleteStringList(&p->v_refs);
  165.        DeleteStringList(&p->f_refs);
  166.        DeleteStringList(&p->called);
  167.        Free(p);
  168.        p=n;
  169.       }
  170.     while(p);
  171.    }
  172.  
  173.  Free(file);
  174. }
  175.